unit PingPongAction;

interface
{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

uses Queue, SysUtils, Variants, Windows;

  procedure Ping(const data:Variant);
  procedure Pong(const data:Variant);

implementation

// procedure Ping(round, rounds, showText, startTime: Variant);
procedure Ping(const data:Variant);
var
  c,t:Integer;
begin
  // 0:Current, 1:Total, 2:ShowText, 3:StartTime,
  if data[0] > 0 then begin
    if data[2] then
      WriteLn('Ping(', data[0], ')');

    Send(Pong, data);
  end else begin
    c := data[1];
    t := GetTickCount-data[3]+1;
    WriteLn(Format('PingPong(%d): %d (%d Rounds/sec)', [c,t, (c*1000 div t)]));
  end;
end;

procedure Pong(const data:Variant);
var
  v: Variant;
begin
  v := data;
  // 0:Current, 1:Total, 2:ShowText, 3:StartTime,
  if data[2] then
    WriteLn('Pong(', v[0], ')');
  v[0] := v[0]-1;

  Send(Ping, v);
end;

end.
